home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / cislib_b / relgen.act < prev    next >
Text File  |  1995-04-22  |  6KB  |  310 lines

  1. MODULE ;RELGEN.ACT 
  2.  
  3. ;COPYRIGHT 1984, QMI, JS DeMar 
  4. ;REV. 1.1, March 20, 1984 
  5.  
  6. ;OBJECT CODE RELOCATION GENERATOR for 
  7. ;ACTION! compiled binary-load files. 
  8.  
  9. ;WARNING!!! This program requires 
  10. ;four OPEN files simultaneously. 
  11. ;Be sure that DOS is configured for 
  12. ;this. With DOS 2.0, set $709 equal 
  13. ;to at least 4, rewrite DOS and 
  14. ;reboot. 
  15.  
  16. ;Requires the second file compiled 
  17. ;at any even page increment higher 
  18. ;than the first file, for example: 
  19. ;$3000 and $3100. 
  20.  
  21. ;Generates a table of the locations 
  22. ;that require relocating and saves 
  23. ;it in a ".GEN" file in ACTION!. 
  24. ;  The ".REL" file is the original 
  25. ;object code with an origin of "0".  
  26. ;The actual relocator is compiled 
  27. ;from the generic relocator source 
  28. ;called "RELOC.ACT" merged with the 
  29. ;".GEN" file generated here. Append 
  30. ;".REL" file to that code and it 
  31. ;will load and relocate to MEMLO. 
  32.  
  33. DEFINE in1="1", 
  34.        in2="2", 
  35.        out1="3", 
  36.        out2="4" 
  37.  
  38. BYTE abrt 
  39.  
  40. ;--------------------------------- 
  41.  
  42. PROC MyError(BYTE a,x,y) 
  43.  
  44. IF y=170 THEN 
  45.   PrintE("ERROR File not found!") 
  46. ELSE 
  47.   Print("ERROR! ") 
  48.   PrintBE(y) 
  49. FI 
  50. abrt=1 
  51. RETURN 
  52. ;--------------------------------- 
  53.  
  54. PROC Ferror() 
  55.  
  56. BYTE t,clock=$14 
  57.  
  58. PrintE("ERROR in Output filespec!") 
  59. t=clock-$80 
  60. DO 
  61. UNTIL t=clock 
  62. OD 
  63. RETURN 
  64. ;--------------------------------- 
  65.  
  66. PROC Main() 
  67.  
  68. CARD start1,start2,end1,end2 
  69. CARD offsets,offsete,i,count,hits 
  70. CARD test1,test2,old1,old2,old3,old0 
  71. BYTE x,z,j,wnum,d1,d2, 
  72.      sthigh 
  73.  
  74. BYTE ARRAY fname1(18),fname2(18), 
  75.            fnameout1(18),fnameout2(18) 
  76.  
  77. DO 
  78. PrintE("}     Relocation Code Generator ") 
  79. PrintE("           JS DeMar 3/84 ") 
  80. PutE() 
  81. PrintE("  Requires two code files compiled") 
  82. PrintE("      with an offset of $0100.") 
  83. PutE() 
  84.  
  85. Print("Filespec for code A >")  
  86. InputMD(device,fname1,18) 
  87. PutE() 
  88. Print("Filespec for code B >")  
  89. InputMD(device,fname2,18) 
  90. PutE() 
  91.  
  92. Scopy(fnameout1,fname1) 
  93. SCopy(fnameout2,fnameout1) 
  94. j=1 
  95. IF fnameout1(1)#'D  
  96.       OR fnameout1(0)<4 THEN 
  97.   Ferror() 
  98. ELSEIF fnameout1(2)=': THEN 
  99.   z=0 
  100. ELSEIF fnameout1(3)=': THEN 
  101.   z=1 
  102. FI 
  103. DO  
  104.   x=fnameout1(j) 
  105.   j==+1 
  106.   IF x=$20 THEN 
  107.     EXIT 
  108.   ELSEIF x='. THEN 
  109.     EXIT 
  110.   ELSEIF j>fnameout1(0) THEN 
  111.     j==+1 
  112.     EXIT 
  113.   ELSEIF j>11+z THEN 
  114.     Ferror() 
  115.   FI 
  116. OD 
  117.  
  118. fnameout1(j-1)='. 
  119. fnameout1(j)='G 
  120. fnameout1(j+1)='E 
  121. fnameout1(j+2)='N 
  122. fnameout1(0)=j+2 
  123.  
  124. j=1 
  125. IF fnameout2(1)#'D  
  126.       OR fnameout2(0)<4 THEN 
  127.   Ferror() 
  128. ELSEIF fnameout2(2)=': THEN 
  129.   z=0 
  130.   EXIT 
  131. ELSEIF fnameout2(3)=': THEN 
  132.   z=1 
  133.   EXIT 
  134. FI 
  135. OD 
  136. DO  
  137.   x=fnameout2(j) 
  138.   j==+1 
  139.   IF x=$20 THEN 
  140.     EXIT 
  141.   ELSEIF x='. THEN 
  142.     EXIT 
  143.   ELSEIF j>fnameout2(0) THEN 
  144.     j==+1 
  145.     EXIT 
  146.   ELSEIF j>11+z THEN 
  147.     Ferror() 
  148.     EXIT 
  149.   FI 
  150. OD 
  151.  
  152. fnameout2(j-1)='. 
  153. fnameout2(j)='R 
  154. fnameout2(j+1)='E 
  155. fnameout2(j+2)='L 
  156. fnameout2(0)=j+2 
  157.  
  158. Print("Generation file = ") 
  159. PrintE(fnameout1) 
  160. Print("Relocation file = ") 
  161. PrintE(fnameout2) 
  162.  
  163. Error=MyError 
  164. abrt=0 
  165. Close(in1) 
  166. Close(in2) 
  167. Close(out1) 
  168. Close(out2) 
  169. Open(in1,fname1,4) 
  170. Open(in2,fname2,4) 
  171. IF abrt=1 THEN  
  172.   Close(1) 
  173.   Close(2) 
  174.   RETURN 
  175. FI 
  176. Open(out1,fnameout1,8) 
  177. Open(out2,fnameout2,8) 
  178.  
  179. x=GetD(in1) ;throw away two $FF's. 
  180. x=GetD(in1) 
  181. PutD(out2,$FF) 
  182. PutD(out2,$FF) 
  183. x=GetD(in1) 
  184. PutD(out2,x) 
  185. start1=x    ;start addr of file1. 
  186. x=GetD(in1) 
  187. PutD(out2,x) 
  188. start1==+(x*256) 
  189. x=GetD(in1) 
  190. PutD(out2,x) 
  191. end1=x 
  192. x=GetD(in1) 
  193. PutD(out2,x) 
  194. end1==+(x*256) ;end addr of file1. 
  195.  
  196. x=GetD(in2) ;throw away two $FF's. 
  197. x=GetD(in2) 
  198. x=GetD(in2) 
  199. start2=x    ;start addr of file2. 
  200. x=GetD(in2) 
  201. start2==+(x*256) 
  202. x=GetD(in2) 
  203. end2=x 
  204. x=GetD(in2) 
  205. end2==+(x*256) ;end addr of file2. 
  206.  
  207. offsets=start2-start1 
  208. sthigh=start1/256 
  209. offsete=end2-end1 
  210.  
  211.  
  212. PrintDE(out1,"MODULE") 
  213. PrintD(out1,";For file ") 
  214. PrintDE(out1,fnameout2) 
  215. PrintDE(out1,"") 
  216. Print("Code starts at ") 
  217. PrintD(out1,"CARD start=[") 
  218. PrintCE(start1) 
  219. PrintCD(out1,start1) 
  220. PrintDE(out1,"]") 
  221. Print("   and ends at ") 
  222. PrintD(out1,"CARD finish=[") 
  223. PrintCE(end1) 
  224. PrintCD(out1,end1) 
  225. PrintDE(out1,"]") 
  226. Print("Compile offset was ") 
  227. PrintCE(offsets) 
  228.  
  229. IF offsete#offsets THEN 
  230.   PrintE("Diferrent size files!") 
  231.   PrintE("ABORTED!") 
  232. ELSE 
  233.   PrintDE(out1,"") 
  234.   PrintD(out1,"CARD ARRAY otable=[") 
  235.   wnum=0 
  236.   hits=0 
  237.   count=0 
  238.   WHILE EOF(in1)=0  
  239.   DO 
  240.     d1=GetD(in1) 
  241.     d2=GetD(in2) 
  242.     IF d1#d2 THEN 
  243.       IF count<(end1-start1)-5 THEN 
  244.         hits==+1 
  245.         IF wnum=0 THEN 
  246.           PrintD(out1,"  ") 
  247.           Print(" ") 
  248.         ElSE  
  249.           PrintD(out1," ") 
  250.           Print(" ") 
  251.         FI 
  252.         PrintCD(out1,count) 
  253.         Print(" ") 
  254.         PrintC(count) 
  255.         wnum==+1 
  256.         IF wnum>4 THEN 
  257.           PrintDE(out1,"") 
  258.           PrintE("") 
  259.           wnum=0 
  260.         FI 
  261.       FI 
  262.       old0=d1 
  263.       test1=old0*256 
  264.       test1==+old1 
  265.       test2=old2*256 
  266.       test2==+old3 
  267.       IF test1>=start1 AND test1<=end1 THEN 
  268.         IF test2=$02E3 OR test2=$02E1 THEN 
  269.           PrintDE(out1,"]") 
  270.           PrintE("]") 
  271.           PrintD(out1,"CARD hits=[") 
  272.           PrintCD(out1,hits) 
  273.           PrintDE(out1,"]") 
  274.           PrintDE(out1,"") 
  275.           Print("CARD hits=[") 
  276.           PrintC(hits) 
  277.           PrintE("]") 
  278.           PrintE("") 
  279.           PrintD(out1,"CARD runaddr=[") 
  280.           Print("CARD runaddr=[") 
  281.           test1==-start1 
  282.           PrintCD(out1,test1) 
  283.           PrintC(test1) 
  284.           PrintDE(out1,"]") 
  285.           PrintE("]") 
  286.           wnum=0 
  287.         FI 
  288.       FI 
  289.       old3=old2 
  290.       old2=old1 
  291.       old1=d1 
  292.       d1==-sthigh 
  293.     ELSE  
  294.       old3=old2 
  295.       old2=old1 
  296.       old1=d1 
  297.     FI 
  298.     PutD(out2,d1) 
  299.     count==+1 
  300.   OD 
  301. FI 
  302. PrintE("") 
  303. PrintDE(out1,"") 
  304. Close(in1) 
  305. Close(in2) 
  306. Close(out1) 
  307. Close(out2) 
  308. PrintE("Finished!}") 
  309. RETURN 
  310.